﻿///#define MSSql
#define MySql

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.Text.RegularExpressions;

using System.IO;
using System.Text;

using System.Net;
using System.Net.Sockets;
using System.Threading;
using System.Net.Mail;

using MySql.Data.MySqlClient;

namespace ukeasbjWeb
{

    public partial class ukeas_bonus_101217 : Bonus
    {
        //从配置文件Web.Config 中读出数据库设置
        ///string strCnn = ConfigurationManager.AppSettings["glCnnStr"];
        ///
        
        protected void Page_Load(object sender, EventArgs e)
        {
            // 在此处放置用户代码以初始化页面
            Common_SXD.Is_LongIn(Response, Session, Request);

            //////只允许顾问、文案、OM、总部会计、Admin 访问
            bool bIs_Counsellor = Convert.ToBoolean(Session["Is_counsellor"]);
            bool bIs_Writer = Convert.ToBoolean(Session["Is_Writer"]);
            bool bIs_O_M = Convert.ToBoolean(Session["Is_O_M"]);
            bool bIs_Admin = Convert.ToBoolean(Session["Is_Admin"]);
            bool bIs_Accountant = Convert.ToBoolean(Session["Is_Accountant"]);

            if (!bIs_Counsellor && !bIs_Writer && !bIs_O_M && !bIs_Admin && !bIs_Accountant)
            {
                Response.Write("<h2 align='center'><font face='宋体' color='red'>");
                Response.Write("<br>对不起，您不能使用本功能。" +
                    "<br>请用其它身份登录。");
                Response.Write("</fong></h2>");
                Response.End();

            }

            if (!IsPostBack)
            {	// 初始化页面

                //暂时关闭
                Bt_Bonus_Exel.Enabled = false;

                //////顾问、文案，设定姓名，关闭选项
                DDList_Counsellor_Writer.Enabled = true;
                DDList_Counsellor_Writer.Visible = true;
                if ((bIs_Counsellor || bIs_Writer))
                    if (!bIs_O_M)
                        if (!bIs_Admin)
                            if (!bIs_Accountant)
                            {
                                DDList_Counsellor_Writer.Enabled = false;
                                DDList_Counsellor_Writer.Visible = false;
                            }

                Init_Office_YearMonth();
                Init_CounsellorWriter();

            }

        }

        /// <summary>
        /// 顾问、文案控件的初始化
        /// </summary>
        private void Init_CounsellorWriter()
        {

            string sDDList_Office = Request["Office"].ToString().Trim();
            sDDList_Office = Common_SXD.get_C_Office(sDDList_Office);

            ///SqlConnection sqlCnn = new SqlConnection(strCnn);

            // 载入顾问、文案数据，绑定到 DDList_Counsellor_Writer 中
            string sSql = "select * from Employees ";
            sSql += "where C_N_Employee like '?' or ( ( Is_Counsellor = 1 or  Is_Writer = 1 ) and Is_Active = 1 and Office ='" + sDDList_Office + "' ) ";
            sSql += "order by Code_Employee asc";
            
            Common_SXD.Init_DropDownList(DDList_Counsellor_Writer, "Employees", sSql);

        }

        /// <summary>
        /// 地区、计奖年、月的初始化
        /// </summary>
        private void Init_Office_YearMonth()
        {
            TextBox_Year_Month.Text = Common_SXD.TimeToYM(DateTime.Now.ToString());
        }

        decimal J1_Jiang, J1_Kou, J5_Jiang, J5_Kou, J7_Jiang, J7_Kou, J2_Jiang, J2_Kou, J8_Jiang, J8_Kou, J3, J4, J6, JJ1, JJ1Add_US;
        int Max_TopPart = 0, Max_MiddlePart = 0, Max_BottomPart = 0;

        /// <summary>
        ///  初始化：计算奖金表，考虑'北京','上海','其他8个办公室'三种计算公式
        /// </summary>
        private void Init_Total_Bonus(string sTime)
        {
            ////////////////////////初始值为空
            Label_b1.Text = "";
            Label_b2.Text = "";

            Label_b3.Text = "";
            Label_b4.Text = "";

            Label_b5.Text = "";
            Label_b6.Text = "";

            Label_b7.Text = "";
            Label_b8.Text = "";

            Label_Total_Not_US.Text = "";
            Label_Total.Text = "";
            Label_Total_US.Text = "";


            Label_Total_Bonus.Text = "";
            ///////////////////////			

            System.DateTime startDateTime20090925 =
                new System.DateTime(2009,        // Year
                9,            // Month
                25,            // Day
                0,            // Hour
                0,            // Minute
                0,            // Second
                0             // Millisecond
                );

            System.DateTime startDateTime20130225 =
                new System.DateTime(2013,        // Year
                2,            // Month
                25,            // Day
                0,            // Hour
                0,            // Minute
                0,            // Second
                0             // Millisecond
                );


            System.DateTime flagStartDateTime = Convert.ToDateTime(Common_SXD.strStartDate);

            JJ1 = J1_Jiang - J1_Kou;
            JJ1Add_US = JJ1 + J5_Jiang - J5_Kou;
            decimal b1 = 0, b2 = 0, b3 = 0, b4 = 0, b5 = 0, b6 = 0;
            string strOffice = Request["Office"].ToString().Trim();
            strOffice = Common_SXD.get_C_Office(strOffice);

            if (strOffice == "北京" && flagStartDateTime <= startDateTime20090925)
            {
                //////////////北京（上海）有30000元指标的奖1
                if (JJ1Add_US < 0 && JJ1 < 0)
                    b1 = Math.Round(JJ1 * 0.05m * 0.333m, 2);
                else if (JJ1 >= 0 && JJ1Add_US < 30000)
                    b1 = 0;
                else if (JJ1Add_US >= 30000 && JJ1Add_US < 50000)
                    b1 = Math.Round(JJ1 * 0.05m * 0.333m, 2);
                else if (JJ1Add_US >= 50000)
                    b1 = Math.Round(JJ1 * 0.05m * 0.333m + JJ1 * 0.01m, 2);

                ///////////////北京奖9
                b3 = Math.Round(J3 * 0.05m * 0.2085m, 2);
                ///////////////北京奖10
                b4 = Math.Round(J4 * 0.05m * 0.2085m, 2);

            }
            else if ( (strOffice == "上海" || (strOffice == "北京" && flagStartDateTime > startDateTime20090925)) 
                && flagStartDateTime < startDateTime20130225 )
            {/// 自2013年3月份起，北京、上海与其他办公室的奖金计算方法相同。
             /// 
                /////////////北京（上海）有30000元指标的奖1
                if (JJ1Add_US < 0 )
                {
                    if (JJ1 < 0)
                        b1 = JJ1 * 0.05m * 0.333m;
                    else
                        b1 = 0;
                    if ((J5_Jiang - J5_Kou) < 0)
                        ///////奖5
                        b5 = Math.Round((J5_Jiang - J5_Kou) * 0.02m, 2);
                    else
                        b5 = 0;
                }
                else if (JJ1Add_US >= 0 && JJ1Add_US < 30000)
                {
                    b1 = 0;
                    ///////奖5
                    b5 = 0;
                }
                else if (JJ1Add_US >= 30000 && JJ1Add_US < 50000)
                {    
                    b1 = JJ1 * 0.05m * 0.333m;
                    ///////奖5
                    b5 = Math.Round((J5_Jiang - J5_Kou) * 0.02m, 2);
                }
                else if (JJ1Add_US >= 50000)
                {    
                    b1 = JJ1 * 0.05m * 0.333m + JJ1 * 0.01m;
                    ///////奖5
                    b5 = Math.Round((J5_Jiang - J5_Kou) * (0.02m + 0.01m), 2);
                }
                b1 = Math.Round(b1, 2);

                

                ///////////////上海奖9
                b3 = Math.Round(J3 * 0.05m * 0.167m, 2);
                //////////////上海奖10
                b4 = Math.Round(J4 * 0.05m * 0.25m, 2);

            }
            else
            {
                ///////无30000元指标的奖1
                ///
                if (JJ1Add_US >= 50000)
                    b1 = JJ1 * 0.05m * 0.333m + JJ1 * 0.01m;
                else
                    b1 = JJ1 * 0.05m * 0.333m;
                b1 = Math.Round(b1, 2);

                ///////
                b3 = Math.Round(J3 * 0.05m * 0.167m, 2);
                //////
                b4 = Math.Round(J4 * 0.05m * 0.25m, 2);
                
                ///////奖5
                b5 = Math.Round((J5_Jiang - J5_Kou) * 0.02m, 2);
                if (JJ1Add_US >= 50000)
                    b5 += Math.Round((J5_Jiang - J5_Kou) * 0.01m, 2);

            }

            ///////奖2
            b2 = Math.Round((J2_Jiang - J2_Kou) * 0.05m * 0.25m, 2);
            ///////奖6
            b6 = Math.Round(J6 * 0.03m, 2);
            ///////奖5
 //           b5 = Math.Round((J5_Jiang - J5_Kou) * 0.02m, 2);
 //           if (JJ1Add_US >= 50000 )
 //               b5 += Math.Round((J5_Jiang - J5_Kou) * 0.01m, 2);

            Label_b1.Text = b1.ToString().Trim();
            Label_b2.Text = b2.ToString().Trim();

            Label_b3.Text = b3.ToString().Trim();
            Label_b4.Text = b4.ToString().Trim();

            Label_b5.Text = b5.ToString().Trim();
            Label_b6.Text = b6.ToString().Trim();

            Label_b7.Text = (J7_Jiang - J7_Kou).ToString().Trim();
            Label_b8.Text = (J8_Jiang - J8_Kou).ToString().Trim();

            Label_Total_US.Text = (J5_Jiang - J5_Kou).ToString().Trim();
            Label_Total_Not_US.Text = JJ1.ToString().Trim();
            Label_Total.Text = (J1_Jiang - J1_Kou + J5_Jiang - J5_Kou).ToString().Trim();

            decimal total = b1 + b2 + b3 + b4 + b5 + b6 + (J7_Jiang - J7_Kou) + (J8_Jiang - J8_Kou);
            total = Math.Round(total, 2);
            Label_Total_Bonus.Text = total.ToString().Trim();

            ////////////////当月签约
            {
                HtmlTableRow row = new HtmlTableRow();

                HtmlTableCell cell = new HtmlTableCell();
                cell.Controls.Add(new LiteralControl(" "));
                row.Cells.Add(cell);

                HtmlTableCell cell2 = new HtmlTableCell();
                cell2.Controls.Add(new LiteralControl("JJ1"));
                row.Cells.Add(cell2);

                HtmlTableCell cell3 = new HtmlTableCell();
                cell3.Controls.Add(new LiteralControl(JJ1.ToString().Trim()));
                row.Cells.Add(cell3);

                //    Table_Bonus_1.Rows.Add(row);

            }
            ///////////////////////////////

        }






        /// <summary>
        ///  初始化奖金8扣奖，文案零中介Offer退约。
        /// </summary>
        /// <remarks>
        /// <newpara>
        /// A) 文案零中介Offer退约，需要扣奖的合同，已经领取奖金，First_Payment >=1000
        ///    2011年7月26日之前
        /// </newpara>
        /// <newpara>
        /// AA) 文案零中介Offer退约，需要扣奖的合同，已经领取奖金，First_Payment >=1000
        ///    2011年7月26日之后
        /// </newpara>
        /// </remarks>
        private void Init_Tables_Bonus8_Kou()
        {

            //清除表中的内容
            Table_Bonus8_Kou.Rows.Clear();
            //J8_Kou = 0;
            SubTotal_Lines J8_KouFilling_Table = new SubTotal_Lines();

            //string strOffice = Request["Office"].ToString().Trim();
            string strCounsellor_Writer;
            if (DDList_Counsellor_Writer.Visible)
            {
                strCounsellor_Writer = DDList_Counsellor_Writer.SelectedItem.Text;
            }
            else
                strCounsellor_Writer = Session["C_N_Employee"].ToString().Trim();

            string sSql = "";
            sSql = "select  Student_Name, 50 as 'Koukuan' from contract where ";

            string strFilter = "";
            /// <newpara>
            /// A) 文案零中介Offer退约，需要扣奖的合同，已经领取奖金，(First_Payment + Second_Payment) >=1000
            ///    2011年7月26日之前
            /// </newpara>
            //strFilter += "Office like '" + strOffice + "' AND";
            strFilter += "( Date_Termination_Refund >= '" + Common_SXD.strStartDate + "' AND  Date_Termination_Refund <= '" + Common_SXD.strEndingDate;
            strFilter += "' ) AND Termination_Refund > 0 AND Date_Completion_Offer > '1930-1-1' AND (Notes like '%deduct%' ) AND (First_Payment + Second_Payment) >= 1000  AND Student_Type = '零中介'  AND Writer = '" + strCounsellor_Writer + "'";
            strFilter += "AND ( Date_Termination_Refund < '2011-7-26' AND Date_Finished_Termination_Refund < '2011-7-26')  ";
            //			sSql += " order by " + Sort_Search_Contract( sSearchKey, sOffice, sStart_Date, sEnd_Date, sSearchValue);

            J8_KouFilling_Table = Filling_Table_with_Heads(sSql + strFilter, J8_KouFilling_Table, 1, Table_Bonus8_Kou);


            //string strOffice = Request["Office"].ToString().Trim();
           
            if (DDList_Counsellor_Writer.Visible)
            {
                strCounsellor_Writer = DDList_Counsellor_Writer.SelectedItem.Text;
            }
            else
                strCounsellor_Writer = Session["C_N_Employee"].ToString().Trim();

            sSql = "";
            sSql = "select  Student_Name, 50 as 'Koukuan' from contract where ";

            strFilter = "";
            /// <newpara>
            /// AA) 文案零中介Offer退约，需要扣奖的合同，已经领取奖金，(First_Payment + Second_Payment) >=1000
            ///    2011年7月26日之后
            /// </newpara>
            //strFilter += "Office like '" + strOffice + "' AND";
            strFilter += "( Date_Finished_Termination_Refund >= '" + Common_SXD.strStartDate + "' AND  Date_Finished_Termination_Refund <= '" + Common_SXD.strEndingDate;
            strFilter += "' ) AND Termination_Refund > 0 AND Date_Completion_Offer > '1930-1-1' AND (Notes like '%deduct%' ) AND (First_Payment + Second_Payment) >= 1000  AND Student_Type = '零中介'  AND Writer = '" + strCounsellor_Writer + "'";
            strFilter += "AND ( Date_Termination_Refund >= '2011-7-26' OR Date_Finished_Termination_Refund >= '2011-7-26' ) ";
            //			sSql += " order by " + Sort_Search_Contract( sSearchKey, sOffice, sStart_Date, sEnd_Date, sSearchValue);

            J8_KouFilling_Table = Filling_Table(sSql + strFilter, J8_KouFilling_Table, 1, Table_Bonus8_Kou);

            J8_Kou = J8_KouFilling_Table.Sub_Total;
            ////////////////生成小计
            {
                HtmlTableRow row = new HtmlTableRow();

                //               HtmlTableCell cell = new HtmlTableCell();
                //               cell.Controls.Add(new LiteralControl(" "));
                //               row.Cells.Add(cell);

                HtmlTableCell cell2 = new HtmlTableCell();
                cell2.Controls.Add(new LiteralControl("合计:"));
                row.Cells.Add(cell2);

                HtmlTableCell cell3 = new HtmlTableCell();
                cell3.Controls.Add(new LiteralControl(J8_Kou.ToString().Trim()));
                row.Cells.Add(cell3);

                Table_Bonus8_Kou.Rows.Add(row);
                //			row.BgColor="Tan";
            }
            ///////////////////////////////

        }



        /// <summary>
        ///  初始化奖金8奖，文案零中介完成Offer奖。
        /// </summary>
        /// <remarks>
        /// <newpara>
        /// A) 文案零中介完成Offer奖， 收到第一个offer，(First_Payment + Second_Payment) >=1000
        /// </newpara>
        /// </remarks>
        private void Init_Tables_Bonus8_Jiang()
        {

            //清除表中的内容
            Table_Bonus8_Jiang.Rows.Clear();
            ///J8_Jiang = 0;
            SubTotal_Lines J8_JiangFilling_Table = new SubTotal_Lines();
            
            //string strOffice = Request["Office"].ToString().Trim();
            string strCounsellor_Writer;
            if (DDList_Counsellor_Writer.Visible)
            {
                strCounsellor_Writer = DDList_Counsellor_Writer.SelectedItem.Text;
            }
            else
                strCounsellor_Writer = Session["C_N_Employee"].ToString().Trim();

            string sSql = "";
            sSql = "select  Student_Name, First_Payment + Second_Payment as 'Yajing', 50  as 'Bonus' from contract where ";

            string strFilter = "";
            /// <newpara>
            /// A) 文案零中介完成Offer奖， 收到第一个offer，(First_Payment + Second_Payment) >=1000
            /// </newpara>
            //strFilter += "Office like '" + strOffice + "' AND";
            strFilter += "( Date_Completion_Offer >= '" + Common_SXD.strStartDate + "' AND  Date_Completion_Offer <= '" + Common_SXD.strEndingDate + "' ) AND (First_Payment + Second_Payment) >= 1000  AND Student_Type = '零中介'  AND Writer = '" + strCounsellor_Writer + "'";

            //			sSql += " order by " + Sort_Search_Contract( sSearchKey, sOffice, sStart_Date, sEnd_Date, sSearchValue);

            J8_JiangFilling_Table = Filling_Table_with_Heads(sSql + strFilter, J8_JiangFilling_Table, 1, Table_Bonus8_Jiang);

            J8_Jiang = J8_JiangFilling_Table.Sub_Total;     
            ////////////////生成小计
            {
                HtmlTableRow row = new HtmlTableRow();

                HtmlTableCell cell = new HtmlTableCell();
                cell.Controls.Add(new LiteralControl(" "));
                row.Cells.Add(cell);

                HtmlTableCell cell2 = new HtmlTableCell();
                cell2.Controls.Add(new LiteralControl("合计:"));
                row.Cells.Add(cell2);

                HtmlTableCell cell3 = new HtmlTableCell();
                cell3.Controls.Add(new LiteralControl(J8_Jiang.ToString().Trim()));
                row.Cells.Add(cell3);

                Table_Bonus8_Jiang.Rows.Add(row);
                //			row.BgColor="Tan";
            }
            ///////////////////////////////

        }


        /// <summary>
        ///  初始化奖金7扣奖，顾问零中介退约
        /// </summary>
        /// <remarks>
        /// <newpara>
        /// A) 本月发生的零中介退款，需要扣奖的合同。
        ///    2011年7月26日之前
        /// </newpara>
        /// <newpara>
        /// AA) 本月发生的零中介退款，需要扣奖的合同。
        ///    2011年7月26日之后
        /// </newpara>
        /// </remarks>
        private void Init_Tables_Bonus7_Kou()
        {

            //清除表中的内容
            Table_Bonus7_Kou.Rows.Clear();
            ///J7_Kou = 0;
            SubTotal_Lines J7_KouFilling_Table = new SubTotal_Lines();

            //string strOffice = Request["Office"].ToString().Trim();
            string strCounsellor_Writer;
            if (DDList_Counsellor_Writer.Visible)
            {
                strCounsellor_Writer = DDList_Counsellor_Writer.SelectedItem.Text;
            }
            else
                strCounsellor_Writer = Session["C_N_Employee"].ToString().Trim();

            string sSql = "";
            sSql = "select  Student_Name, 50  as 'Koukuan' from contract where ";

            string strFilter = "";
            /// <newpara>
            /// A) 本月发生的零中介退款，需要扣奖的合同。
            ///    2011年7月26日之前
            /// </newpara>
            //strFilter += "Office like '" + strOffice + "' AND";
            strFilter += "( Date_Termination_Refund >= '" + Common_SXD.strStartDate + "' AND  Date_Termination_Refund <= '" + Common_SXD.strEndingDate;
            strFilter += "' ) AND Termination_Refund<>0 AND (Notes like '%deduct%' ) AND (First_Payment + Second_Payment) >= 1000  AND Student_Type = '零中介'  AND Counsellor = '" + strCounsellor_Writer + "'";
            strFilter += "AND ( Date_Termination_Refund < '2011-7-26' AND Date_Finished_Termination_Refund < '2011-7-26')  ";
            //			sSql += " order by " + Sort_Search_Contract( sSearchKey, sOffice, sStart_Date, sEnd_Date, sSearchValue);

            J7_KouFilling_Table = Filling_Table_with_Heads(sSql + strFilter, J7_KouFilling_Table, 1, Table_Bonus7_Kou);
            
            
            //string strOffice = Request["Office"].ToString().Trim();
            
            if (DDList_Counsellor_Writer.Visible)
            {
                strCounsellor_Writer = DDList_Counsellor_Writer.SelectedItem.Text;
            }
            else
                strCounsellor_Writer = Session["C_N_Employee"].ToString().Trim();

            sSql = "";
            sSql = "select  Student_Name, 50  as 'Koukuan' from contract where ";
            strFilter = "";
            /// <newpara>
            /// AA) 本月发生的零中介退款，需要扣奖的合同。
            ///    2011年7月26日之后
            /// </newpara>
            //strFilter += "Office like '" + strOffice + "' AND";
            strFilter += "( Date_Finished_Termination_Refund >= '" + Common_SXD.strStartDate + "' AND  Date_Finished_Termination_Refund <= '" + Common_SXD.strEndingDate;
            strFilter += "' ) AND Termination_Refund<>0 AND (Notes like '%deduct%' ) AND (First_Payment + Second_Payment) >= 1000  AND Student_Type = '零中介'  AND Counsellor = '" + strCounsellor_Writer + "'";
            strFilter += "AND ( Date_Termination_Refund >= '2011-7-26' OR Date_Finished_Termination_Refund >= '2011-7-26' ) ";
            //			sSql += " order by " + Sort_Search_Contract( sSearchKey, sOffice, sStart_Date, sEnd_Date, sSearchValue);

            J7_KouFilling_Table = Filling_Table(sSql + strFilter, J7_KouFilling_Table, 1, Table_Bonus7_Kou);

            J7_Kou = J7_KouFilling_Table.Sub_Total;
            ////////////////生成小计
            {
                HtmlTableRow row = new HtmlTableRow();

                //                HtmlTableCell cell = new HtmlTableCell();
                //                cell.Controls.Add(new LiteralControl(" "));
                //                row.Cells.Add(cell);

                HtmlTableCell cell2 = new HtmlTableCell();
                cell2.Controls.Add(new LiteralControl("合计:"));
                row.Cells.Add(cell2);


                HtmlTableCell cell3 = new HtmlTableCell();
                cell3.Controls.Add(new LiteralControl(J7_Kou.ToString().Trim()));
                row.Cells.Add(cell3);

                Table_Bonus7_Kou.Rows.Add(row);
                //			row.BgColor="Tan";
            }
            ///////////////////////////////

        }


        /// <summary>
        ///  初始化奖金7奖，顾问零中介签约奖。
        /// </summary>
        /// <remarks>
        /// <newpara>
        /// A) 本月，第一次付款发生在本月， First_Payment大于等于1000
        /// </newpara>
        /// <newpara>
        /// B) 本月，发生第二次付款， 第一次付款小于1000, 2次款之和大于等于1000。
        /// </newpara>
        /// </remarks>
        private void Init_Tables_Bonus7_Jiang()
        {

            //清除表中的内容
            Table_Bonus7_Jiang.Rows.Clear();
            ///J7_Jiang = 0;
            SubTotal_Lines J7_JiangFilling_Table = new SubTotal_Lines();

            //string strOffice = Request["Office"].ToString().Trim();
            string strCounsellor_Writer;
            if (DDList_Counsellor_Writer.Visible)
            {
                strCounsellor_Writer = DDList_Counsellor_Writer.SelectedItem.Text;
            }
            else
                strCounsellor_Writer = Session["C_N_Employee"].ToString().Trim();

            string sSql = "";
            sSql = "select  Student_Name, First_Payment + Second_Payment as 'Yajing', 50 as 'Bonus'  from contract where ";

            string strFilter = "";
            /// <newpara>
            /// A) 本月，第一次付款发生在本月， First_Payment >=1000
            /// </newpara>
            //strFilter += "Office like '" + strOffice + "' AND";
            strFilter += "((Date_first_payment >= '" + Common_SXD.strStartDate + "') AND (Date_first_payment <= '" + Common_SXD.strEndingDate + "'))  AND First_Payment >= 1000 AND Student_Type = '零中介'  AND counsellor = '" + strCounsellor_Writer + "'";

            //			sSql += " order by " + Sort_Search_Contract( sSearchKey, sOffice, sStart_Date, sEnd_Date, sSearchValue);

            J7_JiangFilling_Table = Filling_Table_with_Heads(sSql + strFilter, J7_JiangFilling_Table, 1, Table_Bonus7_Jiang);
            

            sSql = "select  Student_Name, First_Payment + Second_Payment as 'Yajing', 50 as 'Bonus'  from contract where ";

            /// <newpara>
            /// B) 考虑第二次付款发生在本月， 第一次付款小于1000, 2次款之和大于等于1000。
            /// </newpara>
            strFilter = "";
            //strFilter += "Office like '" + strOffice + "' AND";
            strFilter += "((Date_Second_payment >= '" + Common_SXD.strStartDate + "') AND (Date_Second_payment <= '" + Common_SXD.strEndingDate + "')) AND First_Payment < 1000 AND First_Payment + Second_Payment >= 1000   AND Student_Type = '零中介'  AND counsellor = '" + strCounsellor_Writer + "'";

            //			sSql += " order by " + Sort_Search_Contract( sSearchKey, sOffice, sStart_Date, sEnd_Date, sSearchValue);

            J7_JiangFilling_Table = Filling_Table(sSql + strFilter, J7_JiangFilling_Table, 1, Table_Bonus7_Jiang);

            J7_Jiang = J7_JiangFilling_Table.Sub_Total;
            ////////////////生成小计
            {
                HtmlTableRow row = new HtmlTableRow();

                HtmlTableCell cell = new HtmlTableCell();
                cell.Controls.Add(new LiteralControl(" "));
                row.Cells.Add(cell);

                HtmlTableCell cell2 = new HtmlTableCell();
                cell2.Controls.Add(new LiteralControl("合计:"));
                row.Cells.Add(cell2);

                HtmlTableCell cell3 = new HtmlTableCell();
                cell3.Controls.Add(new LiteralControl(J7_Jiang.ToString().Trim()));
                row.Cells.Add(cell3);

                Table_Bonus7_Jiang.Rows.Add(row);
                //			row.BgColor="Tan";
            }
            ///////////////////////////////

        }

        /// <summary>
        ///  初始化奖金表6，美加合同顾问结案奖
        /// </summary>
        /// <remarks>
        /// <newpara>
        /// A) 顾问结案奖，美国、加拿大全程、申请学校，净收入（一期款 +  二期款 - 退款） 为结案的金额
        /// </newpara>
        /// </remarks>
        private void Init_Tables_Bonus6()
        {

            //清除表中的内容
            Table_Bonus6.Rows.Clear();
            ///J6 = 0;
            SubTotal_Lines J6Filling_Table = new SubTotal_Lines();
            //生成 sql 命令串

            //string strOffice = Request["Office"].ToString().Trim();
            string strCounsellor_Writer;
            if (DDList_Counsellor_Writer.Visible)
            {
                strCounsellor_Writer = DDList_Counsellor_Writer.SelectedItem.Text;
            }
            else
                strCounsellor_Writer = Session["C_N_Employee"].ToString().Trim();

            string sSql = "";

#if MSSql
            sSql = "select  Student_Name, Destinations_OS+':'+Student_Type as Student_Type, First_Payment + Second_Payment - Termination_Refund as 'Shishoujinge' from contract where ";

#elif MySql
            sSql = "select  Student_Name, CONCAT(Destinations_OS, ':', Student_Type) as Student_Type, First_Payment + Second_Payment - Termination_Refund as 'Shishoujinge' from contract where ";

#endif

            string strFilter = "";
            /// <newpara>
            /// A) 顾问结案奖，美国、加拿大全程、申请学校，净收入（一期款 +  二期款 - 退款） 为结案的金额
            /// </newpara>
            //strFilter += "Office like '" + strOffice + "' AND";
            strFilter += "((Date_Completion_Contract >= '" + Common_SXD.strStartDate + "') AND (Date_Completion_Contract <= '" + Common_SXD.strEndingDate;
            strFilter += "')) AND ( Destinations_OS like '美国' OR Destinations_OS like '加拿大' ) AND ( Student_Type like '全程%' OR  Student_Type like '申请学校' )  AND Counsellor = '" + strCounsellor_Writer + "'";

            //			sSql += " order by " + Sort_Search_Contract( sSearchKey, sOffice, sStart_Date, sEnd_Date, sSearchValue);

            J6Filling_Table = Filling_Table_with_Heads(sSql + strFilter, J6Filling_Table, 1, Table_Bonus6);

            J6 = J6Filling_Table.Sub_Total;
            ////////////////生成小计
            {
                HtmlTableRow row = new HtmlTableRow();

                HtmlTableCell cell = new HtmlTableCell();
                cell.Controls.Add(new LiteralControl(" "));
                row.Cells.Add(cell);

                HtmlTableCell cell2 = new HtmlTableCell();
                cell2.Controls.Add(new LiteralControl("合计:"));
                row.Cells.Add(cell2);

                HtmlTableCell cell3 = new HtmlTableCell();
                cell3.Controls.Add(new LiteralControl(J6.ToString().Trim()));
                row.Cells.Add(cell3);

                Table_Bonus6.Rows.Add(row);
                //			row.BgColor="Tan";
            }
            ///////////////////////////////

        }


        /// <summary>
        ///  初始化奖金表3，顾问结案奖
        /// </summary>
        /// <remarks>
        /// <newpara>
        /// A) 顾问结案奖，4种合同，净收入（一期款 +  二期款 - 退款） 为结案的金额
        /// </newpara>
        /// <newpara>
        /// B) 顾问结案奖，4种合同，净收入（一期款 - 退款） 为结案的金额
        /// </newpara>
        /// </remarks>
        private void Init_Tables_Bonus3()
        {

            //清除表中的内容
            Table_Bonus3.Rows.Clear();
            SubTotal_Lines J3Filling_Table = new SubTotal_Lines();

            //生成 sql 命令串

            //string strOffice = Request["Office"].ToString().Trim();
            string strCounsellor_Writer;
            if (DDList_Counsellor_Writer.Visible)
            {
                strCounsellor_Writer = DDList_Counsellor_Writer.SelectedItem.Text;
            }
            else
                strCounsellor_Writer = Session["C_N_Employee"].ToString().Trim();

            string sSql = "";

            
#if MSSql
            sSql = "select  Student_Name, Destinations_OS+':'+Student_Type as Student_Type, First_Payment + Second_Payment - Termination_Refund as 'Shishoujinge' from contract where ";
#elif MySql
            sSql = "select  Student_Name, CONCAT(Destinations_OS, ':', Student_Type) as Student_Type, First_Payment + Second_Payment - Termination_Refund as 'Shishoujinge' from contract where ";
            
#endif

            string strFilter = "";
            /// <newpara>
            /// A) 顾问结案奖，4种合同，净收入（一期款 +  二期款 - 退款） 为结案的金额
            /// </newpara>
            strFilter += "(Date_first_payment >= '1930-1-1') AND (Date_first_payment <= Date_Completion_Contract )";
            strFilter += " AND (Date_second_payment >= '1930-1-1') AND (Date_second_payment <= Date_Completion_Contract ) AND";
            strFilter += " ( First_payment + Second_payment - Termination_Refund) > 0 AND";

            strFilter += "((Date_Completion_Contract >= '" + Common_SXD.strStartDate + "') AND (Date_Completion_Contract <= '" + Common_SXD.strEndingDate;
            strFilter += "')) AND ( ( Student_Type like '全程%' AND Destinations_OS not like '美国' AND Destinations_OS not like '加拿大' ) OR  Student_Type like '%联办' OR ( Student_Type like '申请学校' AND Destinations_OS not like '美国' AND Destinations_OS not like '加拿大' ) OR  Student_Type like '%签证' OR Student_Type like '%文书' )  AND Counsellor = '" + strCounsellor_Writer + "'";

            //			sSql += " order by " + Sort_Search_Contract( sSearchKey, sOffice, sStart_Date, sEnd_Date, sSearchValue);

            J3Filling_Table = Filling_Table_with_Heads(sSql + strFilter, J3Filling_Table, 1, Table_Bonus3);
            
            
            //生成 sql 命令串
            sSql = "";
            
#if MSSql
            sSql = "select  Student_Name, Destinations_OS+':'+Student_Type as Student_Type, First_Payment - Termination_Refund as 'Shishoujinge' from contract where ";
#elif MySql
            sSql = "select  Student_Name, Destinations_OS+':'+Student_Type as Student_Type, First_Payment - Termination_Refund as 'Shishoujinge' from contract where ";
            
#endif

            strFilter = "";
            /// <newpara>
            /// B) 顾问结案奖，4种合同，净收入（一期款 - 退款） 为结案的金额
            /// </newpara>
            strFilter += "(Date_first_payment >= '1930-1-1') AND (Date_first_payment <= Date_Completion_Contract )";
            strFilter += " AND (Date_second_payment < '1930-1-1') AND ";
            strFilter += " ( First_payment + Second_payment - Termination_Refund) > 0 AND";

            strFilter += "((Date_Completion_Contract >= '" + Common_SXD.strStartDate + "') AND (Date_Completion_Contract <= '" + Common_SXD.strEndingDate;
            strFilter += "')) AND ( ( Student_Type like '全程%' AND Destinations_OS not like '美国' AND Destinations_OS not like '加拿大' ) OR  Student_Type like '%联办' OR ( Student_Type like '申请学校' AND Destinations_OS not like '美国' AND Destinations_OS not like '加拿大' ) OR  Student_Type like '%签证' OR Student_Type like '%文书'  )  AND Counsellor = '" + strCounsellor_Writer + "'";

            //			sSql += " order by " + Sort_Search_Contract( sSearchKey, sOffice, sStart_Date, sEnd_Date, sSearchValue);

            J3Filling_Table = Filling_Table(sSql + strFilter, J3Filling_Table, 1, Table_Bonus3);


            J3 = J3Filling_Table.Sub_Total;

            ////////////////生成小计
            {
                HtmlTableRow row = new HtmlTableRow();

                HtmlTableCell cell = new HtmlTableCell();
                cell.Controls.Add(new LiteralControl(" "));
                row.Cells.Add(cell);

                HtmlTableCell cell2 = new HtmlTableCell();
                cell2.Controls.Add(new LiteralControl("合计:"));
                row.Cells.Add(cell2);

                HtmlTableCell cell3 = new HtmlTableCell();
                cell3.Controls.Add(new LiteralControl(J3.ToString().Trim()));
                row.Cells.Add(cell3);

                Table_Bonus3.Rows.Add(row);
                //			row.BgColor="Tan";
            }
            ///////////////////////////////

        }

        /// <summary>
        ///  初始化奖金4，文案结案奖 
        /// </summary>
        /// <remarks>
        /// <newpara>
        /// A) 文案结案奖，4种合同，净收入（一期款 +  二期款 - 退款） 为结案的金额
        /// </newpara>
        /// <newpara>
        /// B) 文案结案奖，4种合同，净收入（一期款 - 退款） 为结案的金额
        /// </newpara>
        /// </remarks>
        private void Init_Tables_Bonus4()
        {

            //清除表中的内容
            Table_Bonus4.Rows.Clear();
            ///J4 = 0;
            SubTotal_Lines J4Filling_Table = new SubTotal_Lines();

            //生成 sql 命令串

            //string strOffice = Request["Office"].ToString().Trim();
            string strCounsellor_Writer;
            if (DDList_Counsellor_Writer.Visible)
            {
                strCounsellor_Writer = DDList_Counsellor_Writer.SelectedItem.Text;
            }
            else
                strCounsellor_Writer = Session["C_N_Employee"].ToString().Trim();

            string sSql = "", strFilter;

            
#if MSSql
            sSql = "select  Student_Name, Destinations_OS+':'+Student_Type as Student_Type, First_Payment + Second_Payment - Termination_Refund as 'Shishoujinge' from contract where ";
#elif MySql
            sSql = "select  Student_Name, CONCAT(Destinations_OS, ':', Student_Type) as Student_Type, First_Payment + Second_Payment - Termination_Refund as 'Shishoujinge' from contract where ";
            
#endif
            //sSql += "Office like '" + strOffice + "' AND";
            /// <newpara>
            /// A) 文案结案奖，5种合同，净收入（一期款 +  二期款 - 退款） 为结案的金额
            /// </newpara>
            /// 
            strFilter = "";
            strFilter += "(Date_first_payment >= '1930-1-1') AND (Date_first_payment <= Date_Completion_Contract )";
            strFilter += " AND (Date_second_payment >= '1930-1-1') AND (Date_second_payment <= Date_Completion_Contract ) AND";
            strFilter += " ( First_payment + Second_payment - Termination_Refund) > 0 AND";

            strFilter += "((Date_Completion_Contract >= '" + Common_SXD.strStartDate + "') AND (Date_Completion_Contract <= '" + Common_SXD.strEndingDate;
            strFilter += "')) AND ( ( Student_Type like '全程%' AND Destinations_OS not like '美国' AND Destinations_OS not like '加拿大' ) OR ( Student_Type like '申请学校' AND Destinations_OS not like '美国' AND Destinations_OS not like '加拿大') OR  Student_Type like '%签证' OR Student_Type like '%文书' OR ( Student_Type like '%联办' AND Destinations_OS not like '%美%' AND Destinations_OS not like '%加%') )  AND Writer = '" + strCounsellor_Writer + "'";

            J4Filling_Table = Filling_Table_with_Heads(sSql + strFilter, J4Filling_Table, 1, Table_Bonus4);
                
            //生成 sql 命令串
            sSql = "";
            
#if MSSql
            sSql = "select  Student_Name, Destinations_OS+':'+Student_Type as Student_Type, First_Payment - Termination_Refund as 'Shishoujinge' from contract where ";
#elif MySql
            sSql = "select  Student_Name, CONCAT(Destinations_OS, ':', Student_Type) as Student_Type, First_Payment - Termination_Refund as 'Shishoujinge' from contract where ";
            
#endif
            //sSql += "Office like '" + strOffice + "' AND";
            /// <newpara>
            /// B) 文案结案奖，5种合同，净收入（一期款 - 退款） 为结案的金额
            /// </newpara>
            /// 
            strFilter = "";
            strFilter += "(Date_first_payment >= '1930-1-1') AND (Date_first_payment <= Date_Completion_Contract )";
            strFilter += " AND (Date_second_payment < '1930-1-1') AND";
            strFilter += " ( First_payment + Second_payment - Termination_Refund) > 0 AND";

            strFilter += "((Date_Completion_Contract >= '" + Common_SXD.strStartDate + "') AND (Date_Completion_Contract <= '" + Common_SXD.strEndingDate;
            strFilter += "')) AND ( ( Student_Type like '全程%' AND Destinations_OS not like '美国' AND Destinations_OS not like '加拿大' ) OR ( Student_Type like '申请学校'  AND Destinations_OS not like '美国' AND Destinations_OS not like '加拿大' ) OR  Student_Type like '%签证' OR Student_Type like '%文书' OR ( Student_Type like '%联办' AND Destinations_OS not like '%美%' AND Destinations_OS not like '%加%') )  AND Writer = '" + strCounsellor_Writer + "'";

            J4Filling_Table = Filling_Table(sSql + strFilter, J4Filling_Table, 1, Table_Bonus4);

            J4 = J4Filling_Table.Sub_Total;
            ////////////////生成小计
            {
                HtmlTableRow row = new HtmlTableRow();

                HtmlTableCell cell = new HtmlTableCell();
                cell.Controls.Add(new LiteralControl(" "));
                row.Cells.Add(cell);

                HtmlTableCell cell2 = new HtmlTableCell();
                cell2.Controls.Add(new LiteralControl("合计:"));
                row.Cells.Add(cell2);

                HtmlTableCell cell3 = new HtmlTableCell();
                cell3.Controls.Add(new LiteralControl(J4.ToString().Trim()));
                row.Cells.Add(cell3);

                Table_Bonus4.Rows.Add(row);
                //			row.BgColor="Tan";
            }
            ///////////////////////////////

        }


        /// <summary>
        ///  初始化奖金2，文案收费生完成Offer/Visa奖
        /// </summary>
        /// <remarks>
        /// <newpara>
        /// A) '全程一次'， '%联办'（不含英美联办），'申请学校'offer完成奖
        /// </newpara>
        /// <newpara>
        /// B) '全程二次'的一期款， 文案offer完成奖。
        /// </newpara>
        /// <newpara>
        /// C) '全程二次'的二期款，visa完成奖。
        /// </newpara>
        /// <newpara>
        /// D) '签证'，visa文案奖2， '%文书' 文案奖2。
        /// </newpara>
        /// <newpara>
        /// E) '联办（不含美）'， 英国文案的奖2。
        /// </newpara>
        /// </remarks>
        private void Init_Tables_Bonus2_Jiang()
        {
            //int MyLines = 0;
            //清除表中的内容
            Table_Bonus2_Jiang.Rows.Clear();
            
            //J2_Jiang = 0;
            SubTotal_Lines J2_JiangReturn_Filling_Table = new SubTotal_Lines();
            
            //string strOffice = Request["Office"].ToString().Trim();
            string strCounsellor_Writer;
            if (DDList_Counsellor_Writer.Visible)
            {
                strCounsellor_Writer = DDList_Counsellor_Writer.SelectedItem.Text;
            }
            else
                strCounsellor_Writer = Session["C_N_Employee"].ToString().Trim();

            string sSql = "";

            
#if MSSql
            sSql = "select  Student_Name, Destinations_OS+':'+Student_Type as Student_Type, First_Payment + Second_Payment as 'Shishoujinge' from contract where ";
#elif MySql
            sSql = "select  Student_Name, CONCAT(Destinations_OS, ':', Student_Type) as Student_Type, First_Payment + Second_Payment as 'Shishoujinge' from contract where ";
            
#endif

            string strFilter = "";
            /// <newpara>
            /// A) '全程一次'， '申请学校'offer完成奖， 不包括但美国全程与单美国申请
            /// </newpara>
            strFilter += "((Date_Completion_Offer >= '" + Common_SXD.strStartDate + "') AND (Date_Completion_Offer <= '" + Common_SXD.strEndingDate;
            strFilter += "')) AND Destinations_OS not like '美国' AND ( Student_Type = '全程一次' OR Student_Type = '申请学校' )  AND Writer = '" + strCounsellor_Writer + "'";

            //			sSql += " order by " + Sort_Search_Contract( sSearchKey, sOffice, sStart_Date, sEnd_Date, sSearchValue);

            J2_JiangReturn_Filling_Table = Filling_Table_with_Heads(sSql + strFilter, J2_JiangReturn_Filling_Table, 1, Table_Bonus2_Jiang);
            
            ///////////////////////////////////////////////////////
            sSql = "";
            
#if MSSql
            sSql = "select  Student_Name, Destinations_OS+':'+Student_Type as Student_Type, First_Payment as 'Shishoujinge' from contract where ";
#elif MySql
            sSql = "select  Student_Name, CONCAT(Destinations_OS, ':', Student_Type) as Student_Type, First_Payment as 'Shishoujinge' from contract where ";
            
#endif
            strFilter = "";
            /// <newpara>
            /// B) '全程二次'的一期款， 文案offer完成奖。
            /// </newpara>
            //strFilter += "Office like '" + strOffice + "' AND";
            strFilter += "((Date_Completion_Offer >= '" + Common_SXD.strStartDate + "') AND (Date_Completion_Offer <= '" + Common_SXD.strEndingDate;
            strFilter += "')) AND Destinations_OS not like '美国' AND  Student_Type = '全程二次'  AND Writer = '" + strCounsellor_Writer + "'";

            //			sSql += " order by " + Sort_Search_Contract( sSearchKey, sOffice, sStart_Date, sEnd_Date, sSearchValue);

            ///////////////////////////////////////////////////////////////////

            J2_JiangReturn_Filling_Table =  Filling_Table(sSql + strFilter, J2_JiangReturn_Filling_Table, 1, Table_Bonus2_Jiang);

            //strOffice = Request["Office"].ToString().Trim();

            //if (DDList_Counsellor_Writer.Visible)
            //{
            //    strCounsellor_Writer = DDList_Counsellor_Writer.SelectedItem.Text;
            //}
            //else
            //    strCounsellor_Writer = Session["C_N_Employee"].ToString().Trim();
            
            sSql = "";
            
#if MSSql
            sSql = "select  Student_Name, Destinations_OS+':'+Student_Type as Student_Type, Second_Payment as 'Shishoujinge' from contract where ";
#elif MySql
            sSql = "select  Student_Name, CONCAT(Destinations_OS, ':', Student_Type) as Student_Type, Second_Payment as 'Shishoujinge' from contract where ";
            
#endif
            strFilter = "";
            //strFilter += "Office like '" + strOffice + "' AND";
            /// <newpara>
            /// C) '全程二次'的第2次付费, visa完成
            /// </newpara>
            strFilter += "(Date_second_payment >= '1930-1-1') AND (Date_second_payment <= Date_Completion_Contract ) AND";

            strFilter += "((Date_Completion_Contract >= '" + Common_SXD.strStartDate + "') AND (Date_Completion_Contract <= '" + Common_SXD.strEndingDate;
            strFilter += "')) AND Destinations_OS not like '美国' AND  Student_Type = '全程二次'  AND Writer = '" + strCounsellor_Writer + "'";

            //			sSql += " order by " + Sort_Search_Contract( sSearchKey, sOffice, sStart_Date, sEnd_Date, sSearchValue);

            J2_JiangReturn_Filling_Table = Filling_Table(sSql + strFilter, J2_JiangReturn_Filling_Table, 1, Table_Bonus2_Jiang);
            
            sSql = "";
            
#if MSSql
            sSql = "select  Student_Name, Destinations_OS+':'+Student_Type as Student_Type, First_Payment + Second_Payment - Termination_Refund as 'Shishoujinge' from contract where ";
#elif MySql
            sSql = "select  Student_Name, CONCAT(Destinations_OS, ':', Student_Type) as  Student_Type, First_Payment + Second_Payment - Termination_Refund as 'Shishoujinge' from contract where ";
            
#endif
            strFilter = "";
            /// <newpara>
            /// D) '签证'、 '%文书' 文案奖2。
            /// </newpara>
            //strFilter += "Office like '" + strOffice + "' AND";
            strFilter += "((Date_Completion_Contract >= '" + Common_SXD.strStartDate + "') AND (Date_Completion_Contract <= '" + Common_SXD.strEndingDate;
            strFilter += "')) AND ( Student_Type like '%签证' OR Student_Type like '%文书' )  AND Writer = '" + strCounsellor_Writer + "'";

            //			sSql += " order by " + Sort_Search_Contract( sSearchKey, sOffice, sStart_Date, sEnd_Date, sSearchValue);

            J2_JiangReturn_Filling_Table = Filling_Table(sSql + strFilter, J2_JiangReturn_Filling_Table, 1, Table_Bonus2_Jiang);
            
            sSql = "";
            
#if MSSql
            sSql = "select  Student_Name, Destinations_OS+':'+Student_Type as Student_Type, First_Payment + Second_Payment - Termination_Refund as 'Shishoujinge' from contract where ";
#elif MySql
            sSql = "select  Student_Name, CONCAT(Destinations_OS, ':', Student_Type) as Student_Type, First_Payment + Second_Payment - Termination_Refund as 'Shishoujinge' from contract where ";
            
#endif
            strFilter = "";
            /// <newpara>
            /// E) '联办(不含美)'， 文案的奖2。
            /// </newpara>
            strFilter += "((Date_Completion_Offer >= '" + Common_SXD.strStartDate + "') AND (Date_Completion_Offer <= '" + Common_SXD.strEndingDate;
            strFilter += "')) AND Student_Type like '%联办' AND Destinations_OS not like '%美%' AND Writer = '" + strCounsellor_Writer + "'";

            //			sSql += " order by " + Sort_Search_Contract( sSearchKey, sOffice, sStart_Date, sEnd_Date, sSearchValue);

            J2_JiangReturn_Filling_Table = Filling_Table(sSql + strFilter, J2_JiangReturn_Filling_Table, 1, Table_Bonus2_Jiang);
            
            J2_Jiang = J2_JiangReturn_Filling_Table.Sub_Total;
            ////////////////生成小计
            {
                HtmlTableRow row = new HtmlTableRow();

                HtmlTableCell cell = new HtmlTableCell();
                cell.Controls.Add(new LiteralControl(" "));
                row.Cells.Add(cell);

                HtmlTableCell cell2 = new HtmlTableCell();
                cell2.Controls.Add(new LiteralControl("合计:"));
                row.Cells.Add(cell2);

                HtmlTableCell cell3 = new HtmlTableCell();
                cell3.Controls.Add(new LiteralControl(J2_Jiang.ToString().Trim()));
                row.Cells.Add(cell3);

                Table_Bonus2_Jiang.Rows.Add(row);
                //			row.BgColor="Tan";
            }
            ///////////////////////////////
            //if (MyLines > Max_TopPart)
            //    Max_TopPart = MyLines;

            if (J2_JiangReturn_Filling_Table.Lines > Max_TopPart)
                Max_TopPart = J2_JiangReturn_Filling_Table.Lines;
        }

        /// <summary>
        ///  初始化奖金2扣, 文案收费生Offer/Visa退约
        /// </summary>
        /// <remarks>
        /// <newpara>
        /// A) '全程一次'，'申请学校'，offer退约。
        ///    2011年7月26日之前
        /// </newpara>
        /// <newpara>
        /// AA) '全程一次'，'申请学校'，offer退约。
        ///    2011年7月26日之后
        /// </newpara>
        /// <newpara>
        /// B) '全程二次'的 offer 完成退约（第二期合同没有执行）。
        ///    2011年7月26日之前
        /// </newpara>
        /// <newpara>
        /// BB) '全程二次'的 offer 完成退约（第二期合同没有执行）。
        ///    2011年7月26日之后
        /// </newpara>
        /// <newpara>
        /// C) 联办（不含美）退款。退款金额 ，文案扣奖，
        ///    2011年7月26日之前
        /// </newpara>
        /// CC) 联办（不含美）退款。退款金额 ，文案扣奖，
        ///    2011年7月26日之后
        /// </newpara>
        /// </remarks>
        private void Init_Tables_Bonus2_Kou()
        {
            //int MyLines = 0;
            //清除表中的内容
            Table_Bonus2_Kou.Rows.Clear();
            
            //J2_Kou = 0;
            SubTotal_Lines J2_KouFilling_Table = new SubTotal_Lines();
            
            //string strOffice = Request["Office"].ToString().Trim();
            string strCounsellor_Writer;
            if (DDList_Counsellor_Writer.Visible)
            {
                strCounsellor_Writer = DDList_Counsellor_Writer.SelectedItem.Text;
            }
            else
                strCounsellor_Writer = Session["C_N_Employee"].ToString().Trim();

            string sSql = "";
            
#if MSSql
            sSql = "select  Student_Name, Destinations_OS+':'+Student_Type as Student_Type, Termination_Refund as 'Shituijinge' from contract where ";
#elif MySql
            sSql = "select  Student_Name, CONCAT(Destinations_OS, ':', Student_Type) as Student_Type, Termination_Refund as 'Shituijinge' from contract where ";
            
#endif

            string strFilter = "";
            /// <newpara>
            /// A) '全程一次'，'申请学校'，offer退约。
            ///    2011年7月26日之前
            /// </newpara>
            //strFilter += "Office like '" + strOffice + "' AND";
            strFilter += "((Date_Termination_Refund >= '" + Common_SXD.strStartDate + "') AND (Date_Termination_Refund <= '" + Common_SXD.strEndingDate;
            strFilter += "')) AND Date_Completion_Offer > '1930-1-1' AND Destinations_OS not like '美国' AND ( Student_Type = '全程一次' OR  Student_Type = '申请学校' )  AND Writer = '";
            strFilter += strCounsellor_Writer + "'AND Termination_Refund > 0 ";
            strFilter += "AND ( Date_Termination_Refund < '2011-7-26' AND Date_Finished_Termination_Refund < '2011-7-26') ";
            //			sSql += " order by " + Sort_Search_Contract( sSearchKey, sOffice, sStart_Date, sEnd_Date, sSearchValue);

            J2_KouFilling_Table = Filling_Table_with_Heads(sSql + strFilter, J2_KouFilling_Table, 1, Table_Bonus2_Kou);
            
            sSql = "";
            
#if MSSql
            sSql = "select  Student_Name, Destinations_OS+':'+Student_Type as Student_Type, Termination_Refund as 'Shituijinge' from contract where ";
#elif MySql
            sSql = "select  Student_Name, CONCAT(Destinations_OS, ':', Student_Type) as Student_Type, Termination_Refund as 'Shituijinge' from contract where ";
            
#endif
            strFilter = "";
            /// <newpara>
            /// AA) '全程一次'，'申请学校'，offer退约。
            ///    2011年7月26日之后
            /// </newpara>
            //strFilter += "Office like '" + strOffice + "' AND";
            strFilter += "((Date_Finished_Termination_Refund >= '" + Common_SXD.strStartDate + "') AND (Date_Finished_Termination_Refund <= '" + Common_SXD.strEndingDate;
            strFilter += "')) AND Date_Completion_Offer > '1930-1-1' AND Destinations_OS not like '美国' AND ( Student_Type = '全程一次' OR  Student_Type = '申请学校' )  AND Writer = '";
            strFilter += strCounsellor_Writer + "'AND Termination_Refund > 0 ";
            strFilter += "AND ( Date_Termination_Refund >= '2011-7-26' OR Date_Finished_Termination_Refund >= '2011-7-26') ";
            //			sSql += " order by " + Sort_Search_Contract( sSearchKey, sOffice, sStart_Date, sEnd_Date, sSearchValue);

            J2_KouFilling_Table = Filling_Table(sSql + strFilter, J2_KouFilling_Table, 1, Table_Bonus2_Kou);
            
            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#if MSSql
            sSql = "select  Student_Name, Destinations_OS+':'+Student_Type as Student_Type, Termination_Refund as 'Shituijinge' from contract where ";
#elif MySql
            sSql = "select  Student_Name, CONCAT(Destinations_OS, ':', Student_Type) as Student_Type, Termination_Refund as 'Shituijinge' from contract where ";
 
#endif
            strFilter = "";
            /// <newpara>
            /// B) '全程二次'的 offer 完成退约。
            ///    2011年7月26日之前
            /// </newpara>
            //strFilter += "Office like '" + strOffice + "' AND";
            strFilter += "((Date_Termination_Refund >= '" + Common_SXD.strStartDate + "') AND (Date_Termination_Refund <= '" + Common_SXD.strEndingDate;
            strFilter += "')) AND Date_Completion_Offer > '1930-1-1' AND Destinations_OS not like '美国' AND ( Student_Type = '全程二次' )  AND Writer = '";
            strFilter += strCounsellor_Writer + "'AND Termination_Refund > 0 ";
            strFilter += "AND ( Date_Termination_Refund < '2011-7-26' AND Date_Finished_Termination_Refund < '2011-7-26') ";
            //			sSql += " order by " + Sort_Search_Contract( sSearchKey, sOffice, sStart_Date, sEnd_Date, sSearchValue);

            J2_KouFilling_Table = Filling_Table(sSql + strFilter, J2_KouFilling_Table, 1, Table_Bonus2_Kou);
            
            
            
#if MSSql
            sSql = "select  Student_Name, Destinations_OS+':'+Student_Type as Student_Type, Termination_Refund as 'Shituijinge' from contract where ";
#elif MySql
            sSql = "select  Student_Name, CONCAT(Destinations_OS, ':', Student_Type) as Student_Type, Termination_Refund as 'Shituijinge' from contract where ";
            
#endif
            strFilter = "";
            /// <newpara>
            /// BB) '全程二次'的 offer 完成退约。
            ///    2011年7月26日之后
            /// </newpara>
            //strFilter += "Office like '" + strOffice + "' AND";
            strFilter += "((Date_Finished_Termination_Refund >= '" + Common_SXD.strStartDate + "') AND (Date_Finished_Termination_Refund <= '" + Common_SXD.strEndingDate;
            strFilter += "'))  AND Date_Completion_Offer > '1930-1-1' AND Destinations_OS not like '美国' AND ( Student_Type = '全程二次' )  AND Writer = '";
            strFilter += strCounsellor_Writer + "'AND Termination_Refund > 0 ";
            strFilter += "AND ( Date_Termination_Refund >= '2011-7-26' OR Date_Finished_Termination_Refund >= '2011-7-26') ";
            //			sSql += " order by " + Sort_Search_Contract( sSearchKey, sOffice, sStart_Date, sEnd_Date, sSearchValue);

            J2_KouFilling_Table = Filling_Table(sSql + strFilter, J2_KouFilling_Table, 1, Table_Bonus2_Kou);
            
            
#if MSSql
            sSql = "select  Student_Name, Destinations_OS+':'+Student_Type as Student_Type, (Termination_Refund - First_Payment - Second_Payment + 12000) as 'Shituijinge' from contract where ";
#elif MySql
            sSql = "select  Student_Name, CONCAT(Destinations_OS, ':', Student_Type) as Student_Type, (Termination_Refund - First_Payment - Second_Payment + 12000) as 'Shituijinge' from contract where ";
            
#endif
            strFilter = "";
            /// <newpara>
            /// C) 联办（不含美）退款。退款金额 ，文案扣奖，Offer退约。
            ///    2011年7月26日之前
            /// </newpara>
            strFilter += "((Date_Termination_Refund >= '" + Common_SXD.strStartDate + "') AND (Date_Termination_Refund <= '" + Common_SXD.strEndingDate;
            strFilter += "')) AND Date_Completion_Offer > '1930-1-1' AND ( Student_Type like '%联办' AND Destinations_OS not like '%美%' ) AND Writer = '";
            strFilter += strCounsellor_Writer + "'AND Termination_Refund >  First_Payment + Second_Payment - 12000 ";
            strFilter += "AND ( Date_Termination_Refund < '2011-7-26' AND Date_Finished_Termination_Refund < '2011-7-26') ";
            //			sSql += " order by " + Sort_Search_Contract( sSearchKey, sOffice, sStart_Date, sEnd_Date, sSearchValue);

            J2_KouFilling_Table = Filling_Table(sSql + strFilter, J2_KouFilling_Table, 1, Table_Bonus2_Kou);
            
            
#if MSSql
            sSql = "select  Student_Name, Destinations_OS+':'+Student_Type as Student_Type, (Termination_Refund - First_Payment - Second_Payment + 12000) as 'Shituijinge' from contract where ";
#elif MySql
            sSql = "select  Student_Name, CONCAT(Destinations_OS, ':', Student_Type) as Student_Type, (Termination_Refund - First_Payment - Second_Payment + 12000) as 'Shituijinge' from contract where ";
            
#endif
            strFilter = "";
            /// <newpara>
            /// CC) 联办（不含美）退款。退款金额 ，文案扣奖，Offer退约。
            ///    2011年7月26日之后
            /// </newpara>
            strFilter += "((Date_Finished_Termination_Refund >= '" + Common_SXD.strStartDate + "') AND (Date_Finished_Termination_Refund <= '" + Common_SXD.strEndingDate;
            strFilter += "')) AND Date_Completion_Offer > '1930-1-1' AND ( Student_Type like '%联办' AND Destinations_OS not like '%美%' ) AND Writer = '";
            strFilter += strCounsellor_Writer + "'AND Termination_Refund >  First_Payment + Second_Payment - 12000 ";
            strFilter += "AND ( Date_Termination_Refund >= '2011-7-26' OR Date_Finished_Termination_Refund >= '2011-7-26') ";
            //			sSql += " order by " + Sort_Search_Contract( sSearchKey, sOffice, sStart_Date, sEnd_Date, sSearchValue);

            J2_KouFilling_Table = Filling_Table(sSql + strFilter, J2_KouFilling_Table, 1, Table_Bonus2_Kou);

            J2_Kou = J2_KouFilling_Table.Sub_Total;
            ////////////////生成小计
            {
                HtmlTableRow row = new HtmlTableRow();

                HtmlTableCell cell = new HtmlTableCell();
                cell.Controls.Add(new LiteralControl(" "));
                row.Cells.Add(cell);

                HtmlTableCell cell2 = new HtmlTableCell();
                cell2.Controls.Add(new LiteralControl("合计:"));
                row.Cells.Add(cell2);

                HtmlTableCell cell3 = new HtmlTableCell();
                cell3.Controls.Add(new LiteralControl(J2_Kou.ToString().Trim()));
                row.Cells.Add(cell3);

                Table_Bonus2_Kou.Rows.Add(row);
                //			row.BgColor="Tan";
            }
            ///////////////////////////////
            if (J2_KouFilling_Table.Lines > Max_TopPart)
                Max_TopPart = J2_KouFilling_Table.Lines;

        }
        /*
        /////////////////////////
        ///填写带表头的奖金子表
        ////////////////////////
        /// <summary>
        /// 填写奖金子表
        /// </summary>
        /// <param name="sSql"></param>
        /// <param name="Max_nLine"></param>
        /// <param name="My_Table"></param>
        /// <returns>奖金小计</returns>
        private SubTotal_Lines Filling_Table_with_Heads(string sSql, SubTotal_Lines MyReturn_Filling_Table, int nCol_Sub_Total, HtmlTable My_Table)
        {

#if MSSql
            ///打开数据库，获取sqlReader变量
            SqlConnection sqlCnn = new SqlConnection();
            SqlDataReader sqlReader = Common_SXD.Open_MSSqlDataReader(sSql, sqlCnn, "打开数据库出错：", Response);
            // 读入第一个查询结果集， 即 Contract 中的数据
            int nCol = sqlReader.FieldCount;
            //清除表中的内容

#elif MySql
            ///打开数据库，获取sqlReader变量
            MySqlConnection MySqlconn = new MySqlConnection();
            MySqlDataReader MysqlReader = Common_SXD.Open_MySqlDataReader(sSql, MySqlconn, "打开数据库出错：", Response);
            // 读入第一个查询结果集， 即 Contract 中的数据
            int nCol = MysqlReader.FieldCount;
            //清除表中的内容
             
#endif
            
            //首先生成标题行
            {
                HtmlTableRow row = new HtmlTableRow();
                for (int i = 0; i < nCol; i++)
                {
                    // Create a new cell and add it to the Cells collection.
                    HtmlTableCell cell = new HtmlTableCell();
#if MSSql
                    string temp = Common_SXD.English_Chinese(sqlReader.GetName(i));
#elif MySql
                    string temp = Common_SXD.English_Chinese(MysqlReader.GetName(i));
#endif
                    cell.Controls.Add(new LiteralControl(temp.Trim()));
                    row.Cells.Add(cell);
                }

                My_Table.Rows.Add(row);
                row.BgColor = "Tan";
            }
#if MSSql
            sqlReader.Close();
            sqlCnn.Close();
#elif MySql
            MysqlReader.Close();
            MySqlconn.Close();
#endif
            return Filling_Table(sSql, MyReturn_Filling_Table, nCol_Sub_Total, My_Table);
        }

        /////////////////////////
        ///填写奖金子表
        ////////////////////////
        /// <summary>
        /// 填写奖金子表
        /// </summary>
        /// <param name="sSql"></param>
        /// <param name="MyLine"></param>
        /// <param name="nCol_Sub_Total"></param>
        /// <param name="MySub_Total"></param>
        /// <param name="My_Table"></param>
        /// <returns>奖金小计,本次行数</returns>
        /// 
        private SubTotal_Lines Filling_Table(string sSql, SubTotal_Lines MyReturn_Filling_Table, int nCol_Sub_Total, HtmlTable My_Table)
        {
            ///SubTotal_Lines MyFilling_Table = new SubTotal_Lines();
            ///MyFilling_Table.Sub_Total = MySub_Total;
            ///MyFilling_Table.Lines = MyLine;
            
            ///int Lines = MyLine;
#if MSSql
            ///打开数据库，获取sqlReader变量
            SqlConnection sqlCnn = new SqlConnection();
            SqlDataReader sqlReader = Common_SXD.Open_MSSqlDataReader(sSql, sqlCnn, "打开数据库出错：", Response);
            // 读入第一个查询结果集， 即 Contract 中的数据
            int nCol = sqlReader.FieldCount;
            //清除表中的内容

#elif MySql
            ///打开数据库，获取sqlReader变量
            MySqlConnection MySqlconn = new MySqlConnection();
            MySqlDataReader MysqlReader = Common_SXD.Open_MySqlDataReader(sSql, MySqlconn, "打开数据库出错：", Response);
            // 读入第一个查询结果集， 即 Contract 中的数据
            int nCol = MysqlReader.FieldCount;
            //清除表中的内容
             
#endif

            // 依次读出数据
#if MSSql
            while (sqlReader.Read())
#elif MySql
            while (MysqlReader.Read())
#endif
            {
                HtmlTableRow row = new HtmlTableRow();
#if MSSql
                String sNo_Series = sqlReader.GetString(0);
#elif MySql
                String sNo_Series = MysqlReader.GetString(0);
#endif
                for (int i = 0; i < nCol; i++)
                {
                    // Create a new cell and add it to the Cells collection.
                    HtmlTableCell cell = new HtmlTableCell();
#if MSSql
                cell.Controls.Add(new LiteralControl(Common_SXD.TimeToYMD(sqlReader.GetValue(i).ToString())));
                    row.Cells.Add(cell);
                    ///if (i == nCol - 1)
                    if (i == nCol - nCol_Sub_Total)
                        MyReturn_Filling_Table.Sub_Total += Convert.ToDecimal(sqlReader.GetValue(i).ToString());   
#elif MySql
                cell.Controls.Add(new LiteralControl(Common_SXD.TimeToYMD(MysqlReader.GetValue(i).ToString())));
                    row.Cells.Add(cell);
                    if (i == nCol - nCol_Sub_Total)
                        MyReturn_Filling_Table.Sub_Total += Convert.ToDecimal(MysqlReader.GetValue(i).ToString());
#endif


                }
                MyReturn_Filling_Table.Lines = MyReturn_Filling_Table.Lines + 1;
                My_Table.Rows.Add(row);
            }
#if MSSql
            sqlReader.Close(); // 关闭sqDataReader
            sqlCnn.Close(); // 关闭数据库连接
#elif MySql
            MysqlReader.Close(); // 关闭sqDataReader
            MySqlconn.Close(); // 关闭数据库连接
#endif
            ///////////////////////////////////////////////////
            return MyReturn_Filling_Table;
        }

*/



        /// <summary>
        ///  初始化奖金1扣奖，顾问收费生退约
        /// </summary>
        /// <remarks>
        /// <newpara>
        /// A) '全程一次', '%联办'，'全程二次', '申请学校', '%签证', '%文书' 的实际退费金额。对于有3000元指标的办公室，不考虑是否领过奖。
        ///    2011年7月26日之前
        /// </newpara>
        /// <newpara>
        /// AA) '全程一次', '%联办'，'全程二次', '申请学校', '%签证', '%文书' 的实际退费金额。对于有3000元指标的办公室，不考虑是否领过奖。
        ///    2011年7月26日之后
        /// </newpara>
        /// </remarks>
        private void Init_Tables_Bonus1_Kou()
        {

            //清除表中的内容
            Table_Bonus1_Kou.Rows.Clear();
            //			Table_Bonus1_Kou.Rows.Clear();
            //J1_Kou = 0;
            SubTotal_Lines J1_KouFilling_Table = new SubTotal_Lines();
            
            //string strOffice = Request["Office"].ToString().Trim();
            string strCounsellor_Writer;
            if (DDList_Counsellor_Writer.Visible)
            {
                strCounsellor_Writer = DDList_Counsellor_Writer.SelectedItem.Text;
            }
            else
                strCounsellor_Writer = Session["C_N_Employee"].ToString().Trim();

            string sSql = "";

            
#if MSSql
            sSql = "select  Student_Name, Destinations_OS+':'+Student_Type as Student_Type, Termination_Refund as 'Shituijinge' from contract where ";        
#elif MySql
            sSql = "select  Student_Name, CONCAT(Destinations_OS, ':', Student_Type) as Student_Type, Termination_Refund as 'Shituijinge' from contract where ";
#endif

            string strFilter = "";
            /// <newpara>
            ///A) '全程一次', '%联办'，'全程二次', '申请学校', '%签证', '%文书' 的实际退费金额。对于有3000元指标的办公室，不考虑是否领过奖。
            ///    2011年7月26日之前
            ///  </newpara>
            //strFilter += "Office like '" + strOffice + "' AND";
            strFilter += "((Date_Termination_Refund >= '" + Common_SXD.strStartDate + "') AND (Date_Termination_Refund <= '" + Common_SXD.strEndingDate;
            strFilter += "')) AND ( ( Student_Type like '全程%' AND Destinations_OS not like '美国' ) OR  Student_Type like '%联办'  OR ( Student_Type like '申请学校' AND Destinations_OS not like '美国' ) OR  Student_Type like '%签证' OR Student_Type like '%文书' )  AND Counsellor = '";
            strFilter += strCounsellor_Writer + "'AND Termination_Refund > 0 ";
            strFilter += "AND ( Date_Termination_Refund < '2011-7-26' AND Date_Finished_Termination_Refund < '2011-7-26') ";
            //			sSql += " order by " + Sort_Search_Contract( sSearchKey, sOffice, sStart_Date, sEnd_Date, sSearchValue);

            J1_KouFilling_Table = Filling_Table_with_Heads(sSql + strFilter, J1_KouFilling_Table, 1, Table_Bonus1_Kou);

#if MSSql
            sSql = "select  Student_Name, Destinations_OS+':'+Student_Type as Student_Type, Termination_Refund as 'Shituijinge' from contract where ";
#elif MySql
            sSql = "select  Student_Name, CONCAT(Destinations_OS, ':', Student_Type) as Student_Type, Termination_Refund as 'Shituijinge' from contract where ";
#endif

            strFilter = "";
            /// <newpara>
            ///AA) '全程一次', '%联办'，'全程二次', '申请学校', '%签证', '%文书' 的实际退费金额。对于有3000元指标的办公室，不考虑是否领过奖。
            ///    2011年7月26日之后
            ///  </newpara>
            //strFilter += "Office like '" + strOffice + "' AND";
            strFilter += "((Date_Finished_Termination_Refund >= '" + Common_SXD.strStartDate + "') AND (Date_Finished_Termination_Refund <= '" + Common_SXD.strEndingDate;
            strFilter += "')) AND ( ( Student_Type like '全程%' AND Destinations_OS not like '美国' AND Destinations_OS not like '加拿大' ) OR  Student_Type like '%联办'  OR ( Student_Type like '申请学校' AND Destinations_OS not like '美国' AND Destinations_OS not like '加拿大' ) OR  Student_Type like '%签证' OR Student_Type like '%文书' )  AND Counsellor = '";
            strFilter += strCounsellor_Writer + "'AND Termination_Refund > 0 ";
            strFilter += "AND ( Date_Termination_Refund >= '2011-7-26' OR Date_Finished_Termination_Refund >= '2011-7-26' )";
            //			sSql += " order by " + Sort_Search_Contract( sSearchKey, sOffice, sStart_Date, sEnd_Date, sSearchValue);

            J1_KouFilling_Table = Filling_Table(sSql + strFilter, J1_KouFilling_Table, 1, Table_Bonus1_Kou);

            J1_Kou = J1_KouFilling_Table.Sub_Total;
            ////////////////生成小计
            {
                HtmlTableRow row = new HtmlTableRow();

                HtmlTableCell cell = new HtmlTableCell();
                cell.Controls.Add(new LiteralControl(" "));
                row.Cells.Add(cell);

                HtmlTableCell cell2 = new HtmlTableCell();
                cell2.Controls.Add(new LiteralControl("合计:"));
                row.Cells.Add(cell2);

                HtmlTableCell cell3 = new HtmlTableCell();
                cell3.Controls.Add(new LiteralControl(J1_Kou.ToString().Trim()));
                row.Cells.Add(cell3);

                Table_Bonus1_Kou.Rows.Add(row);
                //			row.BgColor="Tan";
            }
            ///////////////////////////////

        }

        /// <summary>
        ///  初始化奖金5扣奖，顾问美国全程与申请学校；加拿大全程与申请学校合同退约
        /// </summary>
        /// <remarks>
        /// <newpara>
        /// A) '单美合同'的实际退费金额。对于有3000元指标的办公室，不考虑是否领过奖。
        ///    2011年7月26日之前
        /// <newpara>
        /// AA) '美国加拿大合同'的实际退费金额。对于有3000元指标的办公室，不考虑是否领过奖。
        ///    2011年7月26日之后
        /// </newpara>
        /// </remarks>
        private void Init_Tables_Bonus5_Kou()
        {

            //清除表中的内容
            Table_Bonus5_Kou.Rows.Clear();
            ///J5_Kou = 0;
            SubTotal_Lines J5_KouFilling_Table = new SubTotal_Lines();

            //string strOffice = Request["Office"].ToString().Trim();
            string strCounsellor_Writer;
            if (DDList_Counsellor_Writer.Visible)
            {
                strCounsellor_Writer = DDList_Counsellor_Writer.SelectedItem.Text;
            }
            else
                strCounsellor_Writer = Session["C_N_Employee"].ToString().Trim();

            string sSql = "";

            
#if MSSql
            sSql = "select  Student_Name, Destinations_OS+':'+Student_Type as Student_Type, Termination_Refund as 'Shituijinge' from contract where ";
#elif MySql
            sSql = "select  Student_Name, CONCAT(Destinations_OS, ':', Student_Type) as Student_Type, Termination_Refund as 'Shituijinge' from contract where ";
            
#endif

            string strFilter = "";
            /// <newpara>
            /// A) '全程一次', '全程二次', '申请学校', 的实际退费金额。对于有3000元指标的办公室，不考虑是否领过奖。
            ///    2011年7月26日之前
            /// </newpara>
            //strFilter += "Office like '" + strOffice +"' AND";
            strFilter += "((Date_Termination_Refund >= '" + Common_SXD.strStartDate + "') AND (Date_Termination_Refund <= '" + Common_SXD.strEndingDate;
            strFilter += "')) AND ( Destinations_OS like '美国' OR Destinations_OS like '加拿大' ) AND ( Student_Type like '全程%' OR  Student_Type like '申请学校' )  AND Counsellor = '";
            strFilter += strCounsellor_Writer + "' AND Termination_Refund > 0 ";
            strFilter += "AND ( Date_Termination_Refund < '2011-7-26' AND Date_Finished_Termination_Refund < '2011-7-26')  ";
            //			sSql += " order by " + Sort_Search_Contract( sSearchKey, sOffice, sStart_Date, sEnd_Date, sSearchValue);

            J5_KouFilling_Table = Filling_Table_with_Heads(sSql + strFilter, J5_KouFilling_Table, 1, Table_Bonus5_Kou);

            //string strOffice = Request["Office"].ToString().Trim();
            
            if (DDList_Counsellor_Writer.Visible)
            {
                strCounsellor_Writer = DDList_Counsellor_Writer.SelectedItem.Text;
            }
            else
                strCounsellor_Writer = Session["C_N_Employee"].ToString().Trim();
            
            sSql = "";
            
#if MSSql
            sSql = "select  Student_Name, Destinations_OS+':'+Student_Type as Student_Type, Termination_Refund as 'Shituijinge' from contract where ";
#elif MySql
            sSql = "select  Student_Name, CONCAT(Destinations_OS, ':', Student_Type) as Student_Type, Termination_Refund as 'Shituijinge' from contract where ";
             
#endif

            strFilter = "";
            /// <newpara>
            /// AA) '全程一次', '全程二次', '申请学校', 的实际退费金额。对于有3000元指标的办公室，不考虑是否领过奖。
            ///    2011年7月26日之后
            /// </newpara>
            //strFilter += "Office like '" + strOffice +"' AND";
            strFilter += "((Date_Finished_Termination_Refund >= '" + Common_SXD.strStartDate + "') AND (Date_Finished_Termination_Refund <= '" + Common_SXD.strEndingDate;
            strFilter += "')) AND ( Destinations_OS like '美国' OR Destinations_OS like '加拿大' ) AND ( Student_Type like '全程%' OR  Student_Type like '申请学校' )  AND Counsellor = '";
            strFilter += strCounsellor_Writer + "' AND Termination_Refund > 0 ";
            strFilter += "AND ( Date_Termination_Refund >= '2011-7-26' OR Date_Finished_Termination_Refund >= '2011-7-26' ) ";
            //			sSql += " order by " + Sort_Search_Contract( sSearchKey, sOffice, sStart_Date, sEnd_Date, sSearchValue);

            J5_KouFilling_Table = Filling_Table(sSql + strFilter, J5_KouFilling_Table, 1, Table_Bonus5_Kou);

            J5_Kou = J5_KouFilling_Table.Sub_Total;
            ////////////////生成小计
            {
                HtmlTableRow row = new HtmlTableRow();

                HtmlTableCell cell = new HtmlTableCell();
                cell.Controls.Add(new LiteralControl(" "));
                row.Cells.Add(cell);

                HtmlTableCell cell2 = new HtmlTableCell();
                cell2.Controls.Add(new LiteralControl("合计:"));
                row.Cells.Add(cell2);

                HtmlTableCell cell3 = new HtmlTableCell();
                cell3.Controls.Add(new LiteralControl(J5_Kou.ToString().Trim()));
                row.Cells.Add(cell3);

                Table_Bonus5_Kou.Rows.Add(row);
                //			row.BgColor="Tan";
            }
            ///////////////////////////////

        }

        /// <summary>
        ///  初始化奖金1奖，顾问收费生签约奖
        /// </summary>
        /// <remarks>
        /// <newpara>
        /// A) 只有一期款发生在本月， 二期款发生在其它月份 
        /// </newpara>
        /// <newpara> 
        /// B) 只有二期款发生在本月， 一期款发生在其他月份 
        /// </newpara>
        /// <newpara> 
        /// C) 二期款、 一期款均发生在本月
        /// </newpara>
        /// </remarks>
        private void Init_Tables_Bonus1_Jiang()
        {

            //清除表中的内容
            Table_Bonus1_Jiang.Rows.Clear();
            SubTotal_Lines J1_JiangReturn_Filling_Table = new SubTotal_Lines();

            /// <newpara> 
            /// 读取地区、顾问（文案）字段
            /// </newpara>
            //string strOffice = Request["Office"].ToString().Trim();
            string strCounsellor_Writer;
            if (DDList_Counsellor_Writer.Visible)
            {
                strCounsellor_Writer = DDList_Counsellor_Writer.SelectedItem.Text;
            }
            else
                strCounsellor_Writer = Session["C_N_Employee"].ToString().Trim();

            string sSql = "";
#if MSSql
            sSql = "select  Student_Name, Destinations_OS+':'+Student_Type as Student_Type, First_Payment as 'Shishoujinge'  from contract where ";        
#elif MySql
            sSql = "select  Student_Name, CONCAT(Destinations_OS, ':', Student_Type) as Student_Type, First_Payment as 'Shishoujinge'  from contract where ";
#endif
            string strFilter = "";
            ///////////////////////////////////////////////////
            /// <newpara> 
            /// A) 只有一期款发生在本月， 二期款发生在其它月份
            /// </newpara>
            
            strFilter += "((Date_first_payment >= '" + Common_SXD.strStartDate + "') AND (Date_first_payment <= '" + Common_SXD.strEndingDate;
            strFilter += "')) AND ((Date_second_payment < '" + Common_SXD.strStartDate + "') OR (Date_second_payment > '" + Common_SXD.strEndingDate;
            strFilter += "')) AND ( ( Student_Type like '全程%' AND Destinations_OS not like '美国' AND Destinations_OS not like '加拿大' ) OR  Student_Type like '%联办'  OR ( Student_Type like '申请学校' AND Destinations_OS not like '美国' AND Destinations_OS not like '加拿大' ) OR  Student_Type like '%签证' OR Student_Type like '%文书' ) AND counsellor = '" + strCounsellor_Writer + "'";

            string sOrder = "";
            sOrder = " order by " + "Series_No DESC";

            J1_JiangReturn_Filling_Table = Filling_Table_with_Heads(sSql + strFilter + sOrder, J1_JiangReturn_Filling_Table, 1, Table_Bonus1_Jiang);

            
#if MSSql
            sSql = "select  Student_Name, Destinations_OS+':'+Student_Type as Student_Type, Second_Payment   from contract where ";
#elif MySql
            sSql = "select  Student_Name, CONCAT(Destinations_OS, ':', Student_Type) as Student_Type, Second_Payment   from contract where ";
#endif
            ///////////////////////////////////////////////////
            /// <newpara> 
            /// B) 二期款发生在本月， 一期款发生在其他月份 
            /// </newpara>
            strFilter = "";
            
            strFilter += "((Date_Second_payment >= '" + Common_SXD.strStartDate + "') AND (Date_Second_payment <= '" + Common_SXD.strEndingDate + "')) AND ((Date_First_payment < '" + Common_SXD.strStartDate + "') OR (Date_First_payment > '" + Common_SXD.strEndingDate;
            strFilter += "'))  AND ( ( Student_Type like '全程%' AND Destinations_OS not like '美国' AND Destinations_OS not like '加拿大' ) OR  Student_Type like '%联办'  OR ( Student_Type like '申请学校' AND Destinations_OS not like '美国' AND Destinations_OS not like '加拿大' ) OR  Student_Type like '%签证' OR Student_Type like '%文书' )  AND counsellor = '" + strCounsellor_Writer + "'";
            //			sSql += " order by " + Sort_Search_Contract( sSearchKey, sOffice, sStart_Date, sEnd_Date, sSearchValue);		

            J1_JiangReturn_Filling_Table = Filling_Table(sSql + strFilter, J1_JiangReturn_Filling_Table, 1, Table_Bonus1_Jiang);

            
#if MSSql
            sSql = "select  Student_Name, Destinations_OS+':'+Student_Type as Student_Type, First_Payment + Second_Payment   from contract where ";
#elif MySql
            sSql = "select  Student_Name, CONCAT(Destinations_OS, ':', Student_Type) as Student_Type, First_Payment + Second_Payment   from contract where ";      
#endif
            ///////////////////////////////////////////////////
            /// <newpara> 
            /// C) 二期款、 一期款均发生在本月
            /// </newpara>
            strFilter = "";
            
            strFilter += "((Date_Second_payment >= '" + Common_SXD.strStartDate + "') AND (Date_Second_payment <= '" + Common_SXD.strEndingDate + "')) AND ((Date_First_payment >= '" + Common_SXD.strStartDate + "') AND (Date_First_payment <= '" + Common_SXD.strEndingDate;
            strFilter += "')) AND ( ( Student_Type like '全程%' AND Destinations_OS not like '美国' AND Destinations_OS not like '加拿大' ) OR  Student_Type like '%联办'  OR ( Student_Type like '申请学校' AND Destinations_OS not like '美国' AND Destinations_OS not like '加拿大' ) OR  Student_Type like '%签证' OR Student_Type like '%文书' ) AND counsellor = '" + strCounsellor_Writer + "'";
            //			sSql += " order by " + Sort_Search_Contract( sSearchKey, sOffice, sStart_Date, sEnd_Date, sSearchValue);

            J1_JiangReturn_Filling_Table = Filling_Table(sSql + strFilter, J1_JiangReturn_Filling_Table, 1, Table_Bonus1_Jiang);


            J1_Jiang = J1_JiangReturn_Filling_Table.Sub_Total;
            ///<newpara>
            /// 生成奖1的小计	
            ///</newpara>
            {
                HtmlTableRow row = new HtmlTableRow();

                HtmlTableCell cell = new HtmlTableCell();
                cell.Controls.Add(new LiteralControl(" "));
                row.Cells.Add(cell);

                HtmlTableCell cell2 = new HtmlTableCell();
                cell2.Controls.Add(new LiteralControl("合计:"));
                row.Cells.Add(cell2);

                HtmlTableCell cell3 = new HtmlTableCell();
                cell3.Controls.Add(new LiteralControl(J1_Jiang.ToString().Trim()));
                row.Cells.Add(cell3);

                Table_Bonus1_Jiang.Rows.Add(row);
                //			row.BgColor="Tan";
            }
            ///////////////////////////////
            
        }

        /// <summary>
        ///  初始化奖金5奖，顾问美国全程与申请学校；加拿大全程与申请学校合同
        /// </summary>
        /// <remarks>
        /// <newpara>
        /// A) 只有一期款发生在本月， 二期款发生在其它月份 
        /// </newpara>
        /// <newpara> 
        /// B) 只有二期款发生在本月， 一期款发生在其他月份 
        /// </newpara>
        /// <newpara> 
        /// C) 二期款、 一期款均发生在本月
        /// </newpara>
        /// </remarks>
        private void Init_Tables_Bonus5_Jiang()
        {

            //清除表中的内容
            Table_Bonus5_Jiang.Rows.Clear();
            ///J5_Jiang = 0;
            SubTotal_Lines J5_JiangFilling_Table = new SubTotal_Lines();
            
            /// <newpara> 
            /// 读取地区、顾问（文案）字段
            /// </newpara>
            //string strOffice = Request["Office"].ToString().Trim();
            string strCounsellor_Writer;
            if (DDList_Counsellor_Writer.Visible)
            {
                strCounsellor_Writer = DDList_Counsellor_Writer.SelectedItem.Text;
            }
            else
                strCounsellor_Writer = Session["C_N_Employee"].ToString().Trim();

            string sSql = "";
            
#if MSSql
            sSql = "select  Student_Name, Destinations_OS+':'+Student_Type as Student_Type, First_Payment as 'Shishoujinge'  from contract where ";
#elif MySql
            sSql = "select  Student_Name, CONCAT(Destinations_OS, ':', Student_Type) as Student_Type, First_Payment as 'Shishoujinge'  from contract where ";
            
#endif

            string strFilter = "";
            /// <newpara> 
            /// A) 只有一期款发生在本月， 二期款发生在其它月份
            /// </newpara>
            //strFilter += "Office like '" + strOffice + "' AND";
            strFilter += "((Date_first_payment >= '" + Common_SXD.strStartDate + "') AND (Date_first_payment <= '" + Common_SXD.strEndingDate;
            strFilter += "')) AND ((Date_second_payment < '" + Common_SXD.strStartDate + "') OR (Date_second_payment > '" + Common_SXD.strEndingDate;
            strFilter += "')) AND ( Destinations_OS like '美国' OR Destinations_OS like '加拿大' ) AND ( Student_Type like '全程%' OR  Student_Type like '申请学校' )  AND counsellor = '" + strCounsellor_Writer + "'";

            string sOrder = "";
            sOrder = " order by " + "Series_No DESC";

            J5_JiangFilling_Table = Filling_Table_with_Heads(sSql + strFilter + sOrder, J5_JiangFilling_Table, 1, Table_Bonus5_Jiang);

            ///////////////////////////////////////////////////
            
            
#if MSSql
            sSql = "select  Student_Name, Destinations_OS+':'+Student_Type as Student_Type, Second_Payment   from contract where ";
#elif MySql
            sSql = "select  Student_Name, CONCAT(Destinations_OS, ':', Student_Type) as Student_Type, Second_Payment   from contract where ";
            
#endif

            /// <newpara> 
            /// B) 二期款发生在本月， 一期款发生在其他月份 
            /// </newpara>
            strFilter = "";
            //strFilter += "Office like '" + strOffice + "' AND";
            strFilter += "((Date_Second_payment >= '" + Common_SXD.strStartDate + "') AND (Date_Second_payment <= '" + Common_SXD.strEndingDate + "')) AND ((Date_First_payment < '" + Common_SXD.strStartDate + "') OR (Date_First_payment > '" + Common_SXD.strEndingDate;
            strFilter += "')) AND ( Destinations_OS like '美国' OR Destinations_OS like '加拿大' ) AND ( Student_Type like '全程%' OR  Student_Type like '申请学校' )  AND counsellor = '" + strCounsellor_Writer + "'";
            //			sSql += " order by " + Sort_Search_Contract( sSearchKey, sOffice, sStart_Date, sEnd_Date, sSearchValue);		

            J5_JiangFilling_Table = Filling_Table(sSql + strFilter, J5_JiangFilling_Table, 1, Table_Bonus5_Jiang);

            
            
#if MSSql
            sSql = "select  Student_Name, Destinations_OS+':'+Student_Type as Student_Type, First_Payment + Second_Payment   from contract where ";
#elif MySql
            sSql = "select  Student_Name, CONCAT(Destinations_OS, ':', Student_Type) as Student_Type, First_Payment + Second_Payment   from contract where ";
            
#endif

            /// <newpara> 
            /// C) 二期款、 一期款均发生在本月
            /// </newpara>
            strFilter = "";
            //strFilter += "Office like '" + strOffice + "' AND";
            strFilter += "((Date_Second_payment >= '" + Common_SXD.strStartDate + "') AND (Date_Second_payment <= '" + Common_SXD.strEndingDate + "')) AND ((Date_First_payment >= '" + Common_SXD.strStartDate + "') AND (Date_First_payment <= '" + Common_SXD.strEndingDate;
            strFilter += "')) AND ( Destinations_OS like '美国' OR Destinations_OS like '加拿大' ) AND ( Student_Type like '全程%' OR  Student_Type like '申请学校' )  AND counsellor = '" + strCounsellor_Writer + "'";
            //			sSql += " order by " + Sort_Search_Contract( sSearchKey, sOffice, sStart_Date, sEnd_Date, sSearchValue);
            J5_JiangFilling_Table = Filling_Table(sSql + strFilter, J5_JiangFilling_Table, 1, Table_Bonus5_Jiang);

            J5_Jiang = J5_JiangFilling_Table.Sub_Total;
            ///<newpara>
            /// 生成奖1的小计	
            ///</newpara>
            {
                HtmlTableRow row = new HtmlTableRow();

                HtmlTableCell cell = new HtmlTableCell();
                cell.Controls.Add(new LiteralControl(" "));
                row.Cells.Add(cell);

                HtmlTableCell cell2 = new HtmlTableCell();
                cell2.Controls.Add(new LiteralControl("合计:"));
                row.Cells.Add(cell2);

                HtmlTableCell cell3 = new HtmlTableCell();
                cell3.Controls.Add(new LiteralControl(J5_Jiang.ToString().Trim()));
                row.Cells.Add(cell3);

                Table_Bonus5_Jiang.Rows.Add(row);
                //			row.BgColor="Tan";
            }
            ///////////////////////////////

        }


        protected void Bt_Refress_Search_Click(object sender, EventArgs e)
        {
            Common_SXD.Kill_Sleep_Threads(Response);
            // 填写奖金计算网页
            Common_SXD.Set_BonusDate(TextBox_Year_Month.Text, false);
            Init_Tables_Bonus1_Jiang();
            Init_Tables_Bonus1_Kou();

            Init_Tables_Bonus5_Jiang();
            Init_Tables_Bonus5_Kou();

            Init_Tables_Bonus2_Jiang();
            Init_Tables_Bonus2_Kou();
            Init_Tables_Bonus3();
            Init_Tables_Bonus4();
            Init_Tables_Bonus6();
            Init_Tables_Bonus7_Jiang();
            Init_Tables_Bonus7_Kou();
            Init_Tables_Bonus8_Jiang();
            Init_Tables_Bonus8_Kou();

            int tMonth = DateTime.Now.Month;
            int tYear = DateTime.Now.Year;
            Init_Total_Bonus(TextBox_Year_Month.Text);

            string strOffice = Request["Office"].ToString().Trim();
            strOffice = Common_SXD.get_C_Office(strOffice);
            string strCounsellor_Writer;
            if (DDList_Counsellor_Writer.Visible)
            {
                strCounsellor_Writer = DDList_Counsellor_Writer.SelectedItem.Text;
            }
            else
                strCounsellor_Writer = Session["C_N_Employee"].ToString().Trim();

            System.DateTime bonusDateTime20101201 =
    new System.DateTime(2010,        // Year
    12,            // Month
    1,            // Day
    0,            // Hour
    0,            // Minute
    0,            // Second
    0             // Millisecond
    );

            string temp = TextBox_Year_Month.Text + "-1";
            System.DateTime bonusNow = Convert.ToDateTime(temp);
            /// excel 奖金表的行数限制，分为上中下3个最大行数。
            if (bonusNow >= bonusDateTime20101201 && Max_TopPart <= 40 && Max_MiddlePart <= 16
                && Max_BottomPart <= 20)
            {
                Bt_Bonus_Exel.Enabled = true; //允许发送 excel格式的(101217版)奖金表
                /*  注释后不生成奖金 execl 文件
                SynchronousSocketClient MyClient = new SynchronousSocketClient();
                // 生成 exel 奖金文件
                MyClient.StartClient(strOffice, strCounsellor_Writer, Common_SXD.tempYear, Common_SXD.tempMonth, Response);
            
                 */
            }
            else
            {
                Bt_Bonus_Exel.Enabled = false;
                Response.Write("无法生成 excel 格式的(101217版)奖金表（日期不合适或者数据超出表格范围）！");

            }

        }

        protected void Bt_Bonus_Exel_Click(object sender, EventArgs e)
        {
            // Response.TransmitFile();
            Sendmail_Bonus_Exel();
        }


        public class SynchronousSocketClient
        {

            public bool StartClient(string strOffice, string strCounsellor_Writer, string tempYear, string tempMonth, HttpResponse myResponse)
            {
                // Data buffer for incoming data.
                byte[] bytes = new byte[1024];

                // Connect to a remote device.
                try
                {
                    // Establish the remote endpoint for the socket.
                    // The name of the
                    // remote device is "host.contoso.com".
                    IPHostEntry ipHostInfo = Dns.GetHostEntry("localhost");
                    IPAddress ipAddress = ipHostInfo.AddressList[0];
                    string temp = ipAddress.ToString().Trim();
                    if( temp == "::1")
                        ipAddress = IPAddress.Parse("127.0.0.1");
                    IPEndPoint remoteEP = new IPEndPoint(ipAddress, 10086);
                    
                    // Create a TCP/IP  socket.
                    Socket sender = new Socket(AddressFamily.InterNetwork,
                        SocketType.Stream, ProtocolType.Tcp);

                    // Connect the socket to the remote endpoint. Catch any errors.
                    try
                    {
                        sender.Connect(remoteEP);
                       
                        Console.WriteLine("Socket connected to {0}",
                            sender.RemoteEndPoint.ToString());

                        // Encode the data string into a byte array.
                        byte[] msg = Encoding.UTF8.GetBytes("MakeBonus3In1 " + strOffice + " " + strCounsellor_Writer + " " + tempYear + " " + tempMonth + "  \r\n");
                        
                        // Send the data through the socket.
                        int bytesSent = sender.Send(msg);

                        // Receive the response from the remote device.
                        int bytesRec = sender.Receive(bytes);
                        Console.WriteLine("Echoed test = {0}",
                            Encoding.ASCII.GetString(bytes, 0, bytesRec));

                        // Release the socket.
                        sender.Shutdown(SocketShutdown.Both);
                        sender.Close();

                    }
                    catch (ArgumentNullException ane)
                    {
                        Console.WriteLine("ArgumentNullException : {0}", ane.ToString());
                        return false;
                    }
                    catch (SocketException se)
                    {
                        Console.WriteLine("SocketException : {0}", se.ToString());
                        return false;
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("Unexpected exception : {0}", e.ToString());
                        return false;
                    }

                }
                catch (Exception e)
                {
                    Console.WriteLine(e.ToString());
                    return false;
                }
                return true;
            }

        }

        /// <summary>
        /// 发送奖金表到您的邮箱
        /// </summary>
        private void Sendmail_Bonus_Exel()
        {
            /// <newpara> 
            /// 读取地区、顾问（文案）字段
            /// </newpara>
            Common_SXD.Set_BonusDate(TextBox_Year_Month.Text, false);

            string strOffice = Request["Office"].ToString().Trim();
            strOffice = Common_SXD.get_C_Office(strOffice);
            string strCounsellor_Writer;
            if (DDList_Counsellor_Writer.Visible)
            {
                strCounsellor_Writer = DDList_Counsellor_Writer.SelectedItem.Text;
            }
            else
                strCounsellor_Writer = Session["C_N_Employee"].ToString().Trim();

            /* 注释后，不生成奖金文件 */
            SynchronousSocketClient MyClient = new SynchronousSocketClient();

            MyClient.StartClient(strOffice, strCounsellor_Writer, Common_SXD.tempYear, Common_SXD.tempMonth, Response); //			StartClient();

            Thread.Sleep(9000);
            /* */
            try
            {
                // 服务器名，端口号
                System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient(Common_SXD.smtp_ukeas, 25);
                smtp.UseDefaultCredentials = false;
                //账户，密码
                smtp.Credentials = new System.Net.NetworkCredential("jianwei_rong@promisingEDU.com", Common_SXD.pwd_jianwei_rong);
                smtp.DeliveryMethod = SmtpDeliveryMethod.Network;

                System.Net.Mail.MailMessage myMsg = new System.Net.Mail.MailMessage();
                //发件人
                myMsg.From = new MailAddress("jianwei_rong@promisingEDU.com", "戎建伟", Encoding.GetEncoding("GB2312"));

                myMsg.SubjectEncoding = Encoding.GetEncoding("GB2312");
                myMsg.BodyEncoding = Encoding.GetEncoding("GB2312");
                myMsg.Subject = strOffice + " " + strCounsellor_Writer + "奖金表";
                myMsg.Body = "本邮件是数据库的(101217版)奖金计算结果，请不要回复邮件。";


                string strEmail = Session["Email"].ToString().Trim();
                //string sAddress_Email = strEmail + "@promisingEDU.com";
                //收件人
                myMsg.To.Add(new MailAddress(Common_SXD.eMail_Replacement(strEmail), "", Encoding.GetEncoding("GB2312")));
                //密送
                ///myMsg.Bcc.Add(new MailAddress("rongjianwei@sina.com", "", Encoding.GetEncoding("GB2312")));

                Response.Charset = "gb2312";

                //读取当前目录的path
                //				string strFilePath = Directory.GetCurrentDirectory();
                //读取服务器物理目录
                string strFilePath = Request.PhysicalApplicationPath;
                Common_SXD.Set_BonusDate(TextBox_Year_Month.Text, false);
                string file = strFilePath + @"..\..\Model_Bonus\" + strOffice + "_" +
                    strCounsellor_Writer + Common_SXD.tempDate + "(101217版)奖金申报表" + ".xls";

                //添加附件
                System.Net.Mail.Attachment attachment = new System.Net.Mail.Attachment(file);
                myMsg.Attachments.Add(attachment);
                myMsg.Priority = System.Net.Mail.MailPriority.Low;
                smtp.Send(myMsg);
                myMsg.Attachments.Remove(attachment);
                attachment.Dispose();

                Response.Clear();
                Response.Write("<li>(101217版)奖金表已经发送！</li>");
                //               MessageBox MyB = new MessageBox(this);
                //               MyB.Show("奖金表已经发送！");

            }
            catch (System.Net.Mail.SmtpException se)
            {
                Response.Write("<li>smtp error.</li>" + se.Message);
            }
            catch (FormatException se)
            {
                Response.Write("<li>format error.</li>" + se.Message);
            }
            catch (System.Exception e)
            {
                Response.Write("<li>system error.</li>" + e.Message + "; Target: " + e.TargetSite);
            }

            Bt_Bonus_Exel.Enabled = false;
        }


    }
}
